<template>
    <div name="HotSearch">
        <div class="rm">
            热门搜索</div>
        <div id="rmBtn">
            <input type="button" :value="v.keyword" v-for="(v,i) in rmSearch" :key="v.sort">
        </div>
        <ul class="" id="list" v-if="ls[0]">
            <li v-for="(v,i) in ls" :key="i">
                <a class="" v-text="v.val"></a>
                <span class="mui-icon mui-icon-closeempty" @click='clearThis(i)'></span>
            </li>
        </ul>
        <div id="qk" v-if="ls[0]">
            <input type="button" value="清空搜索历史" class="clear" @click="clear()">
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            rmSearch: '',//热门搜索词
            ls: '',
        }
    },
    methods: {
        clear() {
            localStorage.clear('val');
            this.ls = [];
        },
        clearThis(i) {
            var keys = JSON.parse(localStorage.getItem('val'));
            keys.splice(i, 1);
            localStorage.setItem('val', JSON.stringify(keys))
            localStorage.getItem('val') ? this.ls = JSON.parse(localStorage.getItem('val')) : this.ls = [];
        }
    },
    created() {
        var that = this;
        localStorage.getItem('val') ? that.ls = JSON.parse(localStorage.getItem('val')) : that.ls = [];
        console.log();
        that.$http({
            url: '/rmSearch',
            method: 'post',
        }).then((res) => {
            that.rmSearch = res.data
            console.log(res.data);
        }).catch((err) => {
            console.log(err)
        })
    }
}
</script>
<style scoped>
.rm {
    font-size: 13px;
    color: #999;
    margin-bottom: 10px;
}

#rmBtn input {
    background-color: transparent;
    color: #c3c3c3;
    border-radius: 30px;
    height: 25px;
    line-height: 0.5;
    margin: 5px;
}

#rmBtn input:active {
    color: #999;
    background-color: #f0f0f0;
}


#list li:nth-child(1),
#list li+li {
    border-bottom: 1px solid #676767;
}

#list {
    margin-top: 8px;
}

#list li {
    display: flex;
    justify-content: space-between;
    padding: 5px 12px;
    align-items: center;
}

#list li a {
    color: #c3c3c3;
}

#qk {
    display: flex;
    margin-top: 10px;
}

#qk .clear {
    margin: auto;
    background-color: transparent;
    color: #c3c3c3;
    border-radius: 30px;
    height: 25px;
    line-height: 0.5;
}
</style>

